import Vue from 'vue';
import message from './message.vue'

let MessageConstructor = Vue.extend(message);
let instance;

const Message = function(options) {
	options = options || {};
	if (typeof options === 'string') {
		options = {
			message: options
		};
	}
	instance = new MessageConstructor({
		data: options,
	});
	instance.$mount();
	document.body.appendChild(instance.$el);
	return instance;
};

['success', 'warning', 'info', 'error'].forEach(type => {
	Message[type] = options => {
		console.log(options, 'options');
		if (typeof options === 'string') {
			options = {
				message: options
			};
		}
		options.type = type;
		return Message(options);
	};
});

export default Message